using UnityEngine;
using UnityEngine.UI;

public class ScreenMenu : MonoBehaviour
{
	public static string screenNameDefault = string.Empty;

	public static ScreenMenu[] screenList = new ScreenMenu[0];

	public static ScreenMenu screenLast = null;

	public string group = string.Empty;

	public Button buttonShow;

	public Button[] buttonsBack = new Button[0];

	private ScreenMenu screenBack;

	private bool started;

	public void Show()
	{
		if (screenLast != null && screenLast != this)
		{
			screenBack = screenLast;
		}
		screenList = GetComponentInParent<Canvas>().GetComponentsInChildren<ScreenMenu>(includeInactive: true);
		for (int i = 0; i < screenList.Length; i++)
		{
			if (screenList[i].group == group)
			{
				screenList[i].Start();
				screenList[i].gameObject.SetActive((screenList[i].gameObject == base.gameObject && screenNameDefault == string.Empty) || screenList[i].gameObject.name == screenNameDefault);
				if (screenList[i].gameObject.activeSelf)
				{
					screenLast = screenList[i];
				}
			}
		}
		screenNameDefault = string.Empty;
	}

	public void CloseBack()
	{
		if (screenBack != null)
		{
			screenBack.Show();
		}
		else
		{
			Close();
		}
	}

	public void Close()
	{
		base.gameObject.SetActive(value: false);
	}

	public bool IsActive()
	{
		return base.gameObject.activeSelf;
	}

	public void Start()
	{
		if (started)
		{
			return;
		}
		started = true;
		for (int i = 0; i < buttonsBack.Length; i++)
		{
			if (buttonsBack[i] != null)
			{
				buttonsBack[i].onClick.AddListener(Show);
			}
		}
		if (buttonShow != null)
		{
			buttonShow.onClick.AddListener(Show);
		}
	}

	private void OnDestroy()
	{
		screenList = new ScreenMenu[0];
	}
}
